package com.itheima.wemedia.controller;


import com.itheima.common.pojo.Result;
import com.itheima.common.utils.RequestContext;
import com.itheima.wemedia.pojo.WmMaterial;
import com.itheima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RestController;
    import com.itheima.core.controller.AbstractCoreController;

import java.time.LocalDateTime;

/**
* <p>
* 自媒体图文素材信息表 控制器</p>
* @author czh
* @since 2021-08-20
*/
@RestController
@RequestMapping("/wmMaterial")
public class WmMaterialController extends AbstractCoreController<WmMaterial> {

    private WmMaterialService wmMaterialService;

    //注入
    @Autowired
    public WmMaterialController(WmMaterialService wmMaterialService) {
        super(wmMaterialService);
        this.wmMaterialService=wmMaterialService;
    }

    /**
     * 素材保存
     */
    @Override
    @PostMapping
    public Result insert(@RequestBody WmMaterial wmMaterial){
        wmMaterial.setUserId(RequestContext.getNodeValue("apUserId"));
        wmMaterial.setType(0);
        wmMaterial.setIsCollection(0);
        wmMaterial.setCreatedTime(LocalDateTime.now());
        wmMaterialService.save(wmMaterial);
        Integer id = wmMaterial.getId();
        return Result.ok(wmMaterial);
    }




}

